package edu.zut.hys.api.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import edu.zut.hys.api.domain.ResponseData;
import edu.zut.hys.api.domain.UserDTO;
import edu.zut.hys.api.holder.LoginUserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 获取登录用户信息接口
 * Created by macro on 2020/6/19.
 */
@RestController
@RequestMapping("/user")
public class UserController{

    @Autowired
    private LoginUserHolder loginUserHolder;

    @GetMapping("/currentUser")
    public UserDTO currentUser() {
        return loginUserHolder.getCurrentUser();
    }

    @GetMapping("/userinfo")
    public String userinfo() {
        ResponseData responseData = new ResponseData();
        responseData.setCode(20000);
        JSONObject data = responseData.getData();
        UserDTO user = loginUserHolder.getCurrentUser();
        data.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        data.put("name",user.getUsername());

        return JSON.toJSONString(responseData);
    }
}
